<script setup>
import { SwitchButton, CaretBottom } from '@element-plus/icons-vue'
import avatar from '@/assets/default.png'
import { ElMessage } from 'element-plus'
import { backendLogoutApi } from '@/api/login.js'
import { useRouter } from 'vue-router'
const router = useRouter()
const userInfo = window.localStorage.getItem('userInfo')
const backendLogout = async () => {
    //调用接口,完成登出
    let result = await backendLogoutApi(userInfo);
    if (result.code === 1) {
        ElMessage.success('登出成功');
        router.push('/');
        return;
    } else {
        ElMessage.error(result.msg ? result.msg : '登出失败');
        return;
    }
}
// 获取当前登录用户用户名
const name = window.localStorage.getItem('name');
</script>

<template>
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <div class="el-aside__logo"></div>
            <el-menu active-text-color="#ffd04b" background-color="#9eb2b7" text-color="#fff" router>
                <el-sub-menu>
                    <template #title>
                        <span>账户管理</span>
                    </template>
                    <el-menu-item index="/backend/employee">
                        <span>员工管理</span>
                    </el-menu-item>
                    <el-menu-item index="/backend/user">
                        <span>用户管理</span>
                    </el-menu-item>
                </el-sub-menu>
                <el-menu-item index="/backend/classify">
                    <span>分类管理</span>
                </el-menu-item>
                <el-menu-item index="/backend/dishes">
                    <span>菜品管理</span>
                </el-menu-item>
                <el-menu-item index="/backend/combination">
                    <span>套餐管理</span>
                </el-menu-item>
                <el-menu-item index="/backend/seats">
                    <span>餐位管理</span>
                </el-menu-item>
                <el-menu-item index="/backend/orders">
                    <span>订单明细</span>
                </el-menu-item>
            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header>
                <div>后台系统欢迎您：<el-text class="mx-1" type="primary" size="large">{{ name }}</el-text></div>
                <el-dropdown placement="bottom-end">
                    <span class="el-dropdown__box">
                        <el-avatar :src="avatar" />
                        <el-icon>
                            <CaretBottom />
                        </el-icon>
                    </span>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="logout" :icon="SwitchButton"
                                @click="backendLogout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <div>
                    <router-view></router-view>
                </div>
            </el-main>
            <!-- 底部区域 -->
            <el-footer>ybl ©2023 Created by ybl</el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: #9eb2b7;

        &__logo {
            height: 120px;
            background: url('@/assets/logo.png') no-repeat center / 120px auto;
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }

    .el-main {
        background: url('@/assets/sy.jpg') no-repeat center / cover;
    }
}
</style>